﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace teavch.Util.Web.UI.Automation.Sample
{
	public partial class frmTest : Form
	{

		AutomaticWebRequest _automaticWebRequest = null;
		
		public frmTest()
		{
			InitializeComponent();
		}

		private void btnTest_Click( object sender, EventArgs e )
		{
			_automaticWebRequest = new AutomaticWebRequest( Application.StartupPath + "\\wuia-cases-to-execute.xml" );

			_automaticWebRequest.AutomaticWebRequestReadyForExecution += _automaticWebRequest_AutomaticWebRequestReadyForExecution;
			_automaticWebRequest.AutomaticWebRequestReadyForNextStep += _automaticWebRequest_AutomaticWebRequestReadyForNextStep;
			_automaticWebRequest.AutomaticWebRequestCompleted += _automaticWebRequest_AutomaticWebRequestCompleted;
			_automaticWebRequest.AutomaticWebRequestCaseCompleted += _automaticWebRequest_AutomaticWebRequestCaseCompleted;
			_automaticWebRequest.AutomaticWebRequestStepCompleted += _automaticWebRequest_AutomaticWebRequestStepCompleted;
			_automaticWebRequest.StartExecution();

			//AutomationElement ae = new AutomationElement();
			//ae.ElementID = "Email";
			//ae.ElementEvent = "";
			//ae.DelayAfterExecute = 1000;
			//ae.ElementEventType = AutomationElementEventType.None;
			//ae.ElementEventStatus = false;
			//ae.Attributes = new List<KeyValuePair<string, string>>();
			//ae.Attributes.Add( new KeyValuePair<string, string>( "value", "#yourgmailid#" ) );
			//_automaticWebRequest.AutomationElements.Add( ae );

			//ae = new AutomationElement();
			//ae.ElementID = "Passwd";
			//ae.ElementEvent = "";
			//ae.DelayAfterExecute = 1000;
			//ae.ElementEventType = AutomationElementEventType.InvokeElementMember;
			//ae.ElementEventStatus = false;
			//ae.Attributes = new List<KeyValuePair<string, string>>();
			//ae.Attributes.Add( new KeyValuePair<string, string>( "value", "#yourgmailpwd#" ) );
			//_automaticWebRequest.AutomationElements.Add( ae );

			//ae = new AutomationElement();
			//ae.ElementID = "signIn";
			//ae.ElementEvent = "onClick";
			//ae.DelayAfterExecute = 1000;
			//ae.ElementEventType = AutomationElementEventType.None;
			//ae.ElementEventStatus = false;
			//ae.Attributes = new List<KeyValuePair<string, string>>();
			//_automaticWebRequest.AutomationElements.Add( ae );
		
		}

		private void _automaticWebRequest_AutomaticWebRequestStepCompleted( object sender, AutomaticWebRequestStepCompletedEventArgs e )
		{
			_automaticWebRequest.ExecuteNextStep();
		}

		private void _automaticWebRequest_AutomaticWebRequestCaseCompleted( object sender, AutomaticWebRequestCaseCompletedEventArgs e )
		{
			_automaticWebRequest.ExecuteNextStep();
		}

		private void _automaticWebRequest_AutomaticWebRequestCompleted( object sender, AutomaticWebRequestCompletedEventArgs e )
		{
			//_automaticWebRequest.ExecuteNextStep();
		}

		private void _automaticWebRequest_AutomaticWebRequestReadyForNextStep( object sender, WebBrowserDocumentCompletedEventArgs e )
		{
			_automaticWebRequest.ExecuteNextStep();
		}

		private void _automaticWebRequest_AutomaticWebRequestReadyForExecution( object sender, WebBrowserDocumentCompletedEventArgs e )
		{
			_automaticWebRequest.ExecuteNextStep();
		}

	}
}
